package com.kede.pay.domain;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.math.BigDecimal;

import com.wechat.pay.java.service.transferbatch.model.TransferDetailInput;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 转账明细表
 * @TableName sy_transfer_log
 */
@TableName(value ="sy_transfer_log")
@Data
public class TransferLog implements Serializable {
    /**
     * 
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 关联批次id 商家批次单号
     */
    @TableField(value = "out_batch_no")
    private String outBatchNo;

    /**
     * 商家明细单号
     */
    @TableField(value = "out_detail_no")
    private String outDetailNo;

    /**
     *  转账金额单位为“分
     */
    @TableField(value = "transfer_amount")
    @NotNull(message = "transferAmount 不可为空")
    private BigDecimal transferAmount;

    /**
     * 转账备注
     */
    @NotEmpty(message = "transferRemark 不可为空")
    @TableField(value = "transfer_remark")
    private String transferRemark;

    /**
     * openid
     */
    @NotEmpty(message = "openid 不可为空")
    @TableField(value = "openid")
    private String openid;

    /**
     * 明细状态  WAIT_PAY: 待确认。待商户确认, 符合免密条件时, 系统会自动扭转为转账中
PROCESSING:转账中。正在处理中，转账结果尚未明确
SUCCESS:转账成功
FAIL:转账失败
     */
    @TableField(value = "detail_status")
    private String detailStatus;

    /**
     * 明细失败原因
     */
    @TableField(value = "fail_reason")
    private String failReason;

    /**
     * 创建时间
     */
    @TableField(value = "createtime",fill = FieldFill.INSERT)
    private Integer createtime;

    /**
     * 更新时间
     */
    @TableField(value = "updatetime",fill = FieldFill.INSERT_UPDATE)
    private Integer updatetime;

    /**
     * 应用发起来源 
     */
    @TableField(value = "type")
    @NotBlank(message = "type 不可为空")
    private String type;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @NotNull(message = "userId 不可为空")
    @TableField(value = "userid")
    private Integer userId;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        TransferLog other = (TransferLog) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getOutBatchNo() == null ? other.getOutBatchNo() == null : this.getOutBatchNo().equals(other.getOutBatchNo()))
            && (this.getOutDetailNo() == null ? other.getOutDetailNo() == null : this.getOutDetailNo().equals(other.getOutDetailNo()))
            && (this.getTransferAmount() == null ? other.getTransferAmount() == null : this.getTransferAmount().equals(other.getTransferAmount()))
            && (this.getTransferRemark() == null ? other.getTransferRemark() == null : this.getTransferRemark().equals(other.getTransferRemark()))
            && (this.getOpenid() == null ? other.getOpenid() == null : this.getOpenid().equals(other.getOpenid()))
            && (this.getDetailStatus() == null ? other.getDetailStatus() == null : this.getDetailStatus().equals(other.getDetailStatus()))
            && (this.getFailReason() == null ? other.getFailReason() == null : this.getFailReason().equals(other.getFailReason()))
            && (this.getCreatetime() == null ? other.getCreatetime() == null : this.getCreatetime().equals(other.getCreatetime()))
            && (this.getUpdatetime() == null ? other.getUpdatetime() == null : this.getUpdatetime().equals(other.getUpdatetime()))
            && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getOutBatchNo() == null) ? 0 : getOutBatchNo().hashCode());
        result = prime * result + ((getOutDetailNo() == null) ? 0 : getOutDetailNo().hashCode());
        result = prime * result + ((getTransferAmount() == null) ? 0 : getTransferAmount().hashCode());
        result = prime * result + ((getTransferRemark() == null) ? 0 : getTransferRemark().hashCode());
        result = prime * result + ((getOpenid() == null) ? 0 : getOpenid().hashCode());
        result = prime * result + ((getDetailStatus() == null) ? 0 : getDetailStatus().hashCode());
        result = prime * result + ((getFailReason() == null) ? 0 : getFailReason().hashCode());
        result = prime * result + ((getCreatetime() == null) ? 0 : getCreatetime().hashCode());
        result = prime * result + ((getUpdatetime() == null) ? 0 : getUpdatetime().hashCode());
        result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", outBatchNo=").append(outBatchNo);
        sb.append(", outDetailNo=").append(outDetailNo);
        sb.append(", transferAmount=").append(transferAmount);
        sb.append(", transferRemark=").append(transferRemark);
        sb.append(", openid=").append(openid);
        sb.append(", detailStatus=").append(detailStatus);
        sb.append(", failReason=").append(failReason);
        sb.append(", createtime=").append(createtime);
        sb.append(", updatetime=").append(updatetime);
        sb.append(", type=").append(type);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    //微信需要Long
    public TransferDetailInput toTransferDetailInput(){
        TransferDetailInput transferDetailInput = new TransferDetailInput();
        transferDetailInput.setTransferAmount(getTransferAmount().multiply(new BigDecimal("100")).longValue());
        transferDetailInput.setTransferRemark(getTransferRemark());
        transferDetailInput.setOpenid(getOpenid());
        transferDetailInput.setOutDetailNo(getOutDetailNo());
        return transferDetailInput;
    }
}